package org.maxgroundstation.groundstation.view;

import java.lang.reflect.Method;

import javax.swing.JTabbedPane;
import javax.swing.plaf.basic.BasicTabbedPaneUI;

import org.maxgroundstation.groundstation.GroundStation;
import org.maxgroundstation.groundstation.view.map.MapPanel;

/**
 * A tabbed panel for viewing data, such as camera video and logs.
 * @author Scott Davis
 * 
 * Copyright (C) 2010  Scott Davis
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
@SuppressWarnings("serial")
public class ViewPanel extends JTabbedPane {
	
	/**
	 * Constructor
	 * @param gs the ground station.
	 */
	public ViewPanel(GroundStation gs) {
		super();
		
		// Add camera tab panel.
		addTab("Camera", new CameraPanel(gs));
		
		// Add map tab panel.
		addTab("Map", new MapPanel(gs));
		
		// Add log tab panel.
		addTab("Log", new LogPanel(gs));
		
		// Remove keyboard bindings for tabs
		// This conflicts with keyboard control of rover.
		removeTabbedPaneKeyboardBinding(this);
	}
	
    /**
     * Removes keyboard bindings from a JTabbedPane component.
     * @param tabPane the tabbed pane component.
     */
    private void removeTabbedPaneKeyboardBinding(JTabbedPane tabPane) {
        try {
            Method uninstallKeyboardActions = BasicTabbedPaneUI.class.getDeclaredMethod("uninstallKeyboardActions",
                    new Class[] { });
            uninstallKeyboardActions.setAccessible(true);
            uninstallKeyboardActions.invoke(tabPane.getUI());
        }
        catch (Exception e) {
            e.printStackTrace(System.err);
        }
    }
}